<template>
	<view class="content">
		<navbarBack></navbarBack>
		<view class="head">
			<view class="line" :style="{ 'margin-top': navHeight + 'px' }">
				<view class="text" style="margin-bottom: 8rpx;">当前</view>
				<view class="money">￥<text class="num1">{{prize}}</text></view>
			</view>
			<view class="line" style="margin-top: 15rpx;">
				<view class="text">累计发放</view>
				<view class="money">￥<text class="num2">{{total}}</text></view>
			</view>
		</view>
		<view class="tab">
			<view class="item" v-for="(item, index) in tabList" :key="index">
				<view :class="item.id == tabId ? 'title-on' : 'title'" @click="onTab(item)">{{ item.title }}</view>
			</view>
		</view>

		<view class="tab-content">
			<view class="box1" v-if="tabId == 1">
				<view class="my" v-if="user.userName">
					<view class="no">
						{{size}}
					</view>
					<image class="avatar"
						:src="user.avatar?user.avatar:'http://sni1muz85.hd-bkt.clouddn.com/img/my/avatar.jpeg'"></image>
					<view class="right">
						<view class="line1">
							<view class="name">{{user.userName?user.userName:""}}</view>
							<view class="day">累计{{user.signNum}}天</view>
						</view>
						<view class="line2">
							<view class="left">
								<view class="text1">
									福利
									<text>{{user.money}}</text>
								</view>
								<view class="text2">
									规则 {{user.times}}

									<!--									<text>20</text>-->
								</view>
							</view>
							<view class="time">{{user.signTime}}</view>
						</view>
					</view>
				</view>

				<view class="list">
					<view class="item" v-for="(item, index) in dataList" :key="index">
						<view class="no">
							<image v-if="index  <= 2"
								:src="index === 0 ? 'http://sni1muz85.hd-bkt.clouddn.com/img/ranking/no1.png' : (index === 1 ? 'http://sni1muz85.hd-bkt.clouddn.com/img/ranking/no2.png' : 'http://sni1muz85.hd-bkt.clouddn.com/img/ranking/no3.png')">
							</image>
							<text v-if="index  > 2"> {{index+1}} </text>
						</view>
						<image class="avatar" :src="item.avatar"></image>
						<view class="right">
							<view class="line1">
								<view class="name">{{ item.userName?item.userName:"" }}</view>
								<view class="day">累计{{ item.signNum }}天</view>
							</view>
							<view class="line2">
								<view class="left">
									<view class="text1">
										福利
										<text>{{item.money}}</text>
									</view>
									<view class="text2">
										规则 {{item.times}}
										<text></text>
									</view>
								</view>
								<view class="time">{{ item.signTime }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="box2" v-if="tabId == 2">
				<view class="list">
					<view class="item" v-for="(item, index) in signList" :key="index">
						<view class="left">
							<image class="avatar"
								:src="item.avatar?item.avatar:'http://sni1muz85.hd-bkt.clouddn.com/img/my/avatar.jpeg'">
							</image>
							<view class="name">{{ item.userName?item.userName:"" }}</view>
						</view>
						<view class="right">
							<view class="money">￥{{ item.total }}</view>
							<view class="time">
								<!--								<text>2023-12-12</text>-->
								<text>{{ item.createTime }}</text>
							</view>

						</view>
					</view>
				</view>
			</view>
			<view class="box3" v-if="tabId == 3">
				{{ruleContent}}
			</view>
		</view>
	</view>
</template>

<script>
	import navbarBack from '../../components/myNavbar/navbarBack.vue'

	export default {
		components: {
			navbarBack
		},
		data() {
			return {
				navHeight: 0, //导航栏高度
				tabId: 1,
				tabList: [{
						id: 1,
						title: "打卡排行"
					},
					{
						id: 2,
						title: "发放记录"
					},
					{
						id: 3,
						title: "规则"
					}
				],
				total: 0,
				size: 999,
				signList: [],
				user: {},
				dataList: [],
				prize: 0,
				ruleContent: ""
			}
		},

		onLoad() {
			// 获取屏幕导航栏高度
			let value = uni.getStorageSync('navHeight')
			this.navHeight = value.height
			if (this.$store.state.rankAd) {
				let ad = wx.createInterstitialAd({
					adUnitId: 'adunit-9042aab733ba906b'
				})
				ad.onError(() => {})
				ad.show().then(() => {
					this.$store.state.rankAd = false
				})
			}
			this.initData()
		},

		methods: {
			onTab(item) {
				this.tabId = item.id
			},
			initData() {
				this.$api.request({
					url: this.$api.publicList,
					data: {
						name: "finance"
					}
				}).then(res => {
					if (res.data.length > 0) {
						this.prize = JSON.parse(res.data[0].value).prize
					}
				})
				this.$api.request({
					url: this.$api.sumMoney,
				}).then(res => {
					this.signList = res.data
				})
				this.$api.request({
					url: this.$api.total,
				}).then(res => {
					this.total = res.data
				})

				this.$api.request({
					url: this.$api.rankList,
				}).then(res => {
					this.size = res.data.size
					this.user = res.data.user
					this.dataList = res.data.list

				})

				this.$api.request({
					url: this.$api.getRuleContent
				}).then(res => {
					this.ruleContent = res.data.explanationText;
				});

			},
		}
	}
</script>

<style lang="less" scoped>
	@import "@/static/css/app.less";

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #fff;
		min-height: 100vh;
		position: relative;

		.head {
			height: 380rpx;
			width: 100%;
			background-color: #07C160;
			display: flex;
			flex-direction: column;
			align-items: center;

			.line {
				display: flex;
				align-items: flex-end;
				color: #fff;
				margin-top: var(--status-bar-height);


				.text {
					font-size: 40rpx;
					// margin-right: 20rpx;
					margin-bottom: 3rpx;
				}

				.money {
					font-size: 40rpx;
					// font-weight: bold;

					.num1 {
						font-size: 70rpx;
					}

					.num2 {
						font-size: 40rpx;
					}
				}
			}

		}

		.tab {
			width: 750rpx;
			display: flex;
			justify-content: center;
			margin-top: 30rpx;
			position: relative;
			top: -50rpx;
			border-radius: @radius_1 @radius_1 0 0;
			background-color: #fff;
			padding: 38rpx 0 20rpx;

			.item {
				margin: 0 20rpx;
				font-size: 36rpx;
				// font-weight: bold;

				.title {
					color: #8A8A8A;
				}

				.title-on {
					color: #000;
					border-bottom: 10rpx solid #07C160;
				}
			}
		}

		.tab-content {
			position: relative;
			top: -50rpx;

			.box1 {
				margin-top: 50rpx;
				width: 690rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.my {
					width: 690rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-bottom: 20rpx;
					border-bottom: 1rpx solid #aaa;

					.no {
						height: 50rpx;
						width: 100rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						color: #07C160;

						image {
							height: 49rpx;
							width: 40rpx;
						}

						text {
							font-size: 28rpx;
							color: #989898;
						}
					}

					.avatar {
						height: 100rpx;
						width: 100rpx;
						border-radius: @radius;
						background-color: #EEEEEE;
						// margin: 30rpx;
					}

					.right {
						width: 500rpx;
						margin-left: 10rpx;

						.line1 {
							display: flex;
							justify-content: space-between;
							align-items: center;

							.name {
								font-size: 32rpx;
								font-weight: bold;
							}

							.day {
								font-size: 32rpx;
							}
						}

						.line2 {
							display: flex;
							justify-content: space-between;
							align-items: center;
							margin-top: 10rpx;

							.left {
								display: flex;
								font-size: 28rpx;

								.text1 {
									color: #FF6241;

									text {
										margin-left: 10rpx;
									}
								}

								.text2 {
									margin-left: 28rpx;
									color: #07C160;

									text {
										margin-left: 10rpx;
									}
								}
							}

							.time {
								font-size: 28rpx;
								color: #B1B1B3;
								text-align: end;
							}
						}
					}
				}

				.list {
					width: 690rpx;

					.item {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 40rpx;

						.no {
							height: 50rpx;
							width: 100rpx;
							display: flex;
							justify-content: center;
							align-items: center;

							image {
								height: 49rpx;
								width: 40rpx;
							}

							text {
								font-size: 28rpx;
								color: #989898;
							}
						}

						.avatar {
							height: 100rpx;
							width: 100rpx;
							border-radius: @radius;
							background-color: #EEEEEE;
							// margin: 30rpx;
						}

						.right {
							width: 500rpx;
							margin-left: 10rpx;

							.line1 {
								display: flex;
								justify-content: space-between;
								align-items: center;

								.name {
									font-size: 32rpx;
									font-weight: bold;
								}

								.day {
									font-size: 32rpx;
								}
							}

							.line2 {
								display: flex;
								justify-content: space-between;
								align-items: center;
								margin-top: 10rpx;

								.left {
									display: flex;
									font-size: 28rpx;

									.text1 {
										color: #FF6241;

										text {
											margin-left: 10rpx;
										}
									}

									.text2 {
										margin-left: 28rpx;
										color: #07C160;

										text {
											margin-left: 10rpx;
										}
									}
								}

								.time {
									font-size: 28rpx;
									color: #B1B1B3;
									text-align: end;
								}
							}
						}
					}
				}
			}

			.box2 {

				// margin-top: 30rpx;

				.list {
					.item {
						width: 690rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-top: 56rpx;

						.left {
							display: flex;
							align-items: center;
							flex: 1;

							.avatar {
								height: 100rpx;
								width: 100rpx;
								border-radius: @radius;
							}

							.name {
								flex: 1;
								font-size: 32rpx;
								font-weight: bold;
								margin-left: 20rpx;
								word-wrap: break-word;

							}
						}

						.right {
							display: flex;
							align-items: flex-end;
							flex-direction: column;
							width: 300rpx;

							.money {
								font-size: 36rpx;
								font-weight: bold;
								margin-right: 40rpx;
							}

							.time {
								//display: flex;
								//flex-direction: column;
								font-size: 28rpx;
								color: #B2A3B6;
								white-space: nowrap;
							}
						}
					}
				}
			}

			.box3 {
				margin-top: 50rpx;
				font-size: 32rpx;
			}
		}


	}
</style>